import { defineConfig } from 'vite';
import { resolve } from 'path';
import uni from '@dcloudio/vite-plugin-uni';

// 自动导入composition api
import AutoImport from 'unplugin-auto-import/vite';
import { autoImportList, lodashList } from './utils/autoImport';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        uni(),
        // 配置自动导入 vue相关函数, uni-app相关函数。ref, reactive，onLoad等
        AutoImport({
            // 自动导入
            imports: [
                'vue',
                'uni-app',
                'pinia',
                {
                    // 使用的时候才会自动导入，检查js代码
                    '@/utils/autoImport': autoImportList,
                    lodash: lodashList,
                    vue: ['h'],
                },
            ],
            dts: '.auto-import.d.ts', // 生成 `auto-import.d.ts` 全局声明
        }),
    ],
    resolve: {
        alias: {
            '@a': resolve(__dirname, './api'),
            '@u': resolve(__dirname, './utils'),
        },
    },
    server: {
        proxy: {
            '/dev-api': {
                target: 'http://localhost:9400', // 服务端地址
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/dev-api/, ''),
            },
        },
    },
});
